home *** CD-ROM | disk | FTP | other *** search
/ Night Owl 9 / Night Owl CD-ROM (NOPV9) (Night Owl Publisher) (1993).ISO / 009a / snpd0493.zip / PMERGE.C < prev    next >
C/C++ Source or Header  |  1993-04-05  |  2KB  |  70 lines

  1. /*
  2. **  pmerge() - Portable replacement for fnmerge(), _makepath(), etc.
  3. **
  4. **  Forms a full DOS pathname from drive, path, file, and extension
  5. **  specifications.
  6. **
  7. **  Arguments: 1 - Buffer to receive full pathname
  8. **             2 - Drive
  9. **             3 - Path
  10. **             4 - Name
  11. **             5 - Extension
  12. **
  13. **  Returns: Nothing
  14. **
  15. **  public domain by Bob Stout
  16. */
  17.  
  18. #include <string.h>
  19.  
  20. #define LAST_CHAR(s) ((s)[strlen(s) - 1])
  21.  
  22. void pmerge(char *path, char *drive, char *dir, char *fname, char *ext)
  23. {
  24.       *path = '\0';
  25.  
  26.       if (drive && *drive)
  27.       {
  28.             strcat(path, drive);
  29.             if (':' != LAST_CHAR(path))
  30.                   strcat(path, ":");
  31.       }
  32.  
  33.       if (dir && *dir)
  34.       {
  35.             char *p;
  36.  
  37.             strcat(path, dir);
  38.             for (p = path; *p; ++p)
  39.                   if ('/' == *p)
  40.                         *p = '\\';
  41.             if ('\\' != LAST_CHAR(path))
  42.                   strcat(path, "\\");
  43.       }
  44.  
  45.       if (fname && *fname)
  46.       {
  47.             strcat(path, fname);
  48.  
  49.             if (ext && *ext)
  50.             {
  51.                   if ('.' != *ext)
  52.                         strcat(path, ".");
  53.                   strcat(path, ext);
  54.             }
  55.       }
  56. }
  57.  
  58. #ifdef TEST
  59.  
  60. #include <stdio.h>
  61.  
  62. int main(int argc, char *argv[])
  63. {
  64.       char pathname[FILENAME_MAX];
  65.  
  66.       pmerge(pathname, argv[1], argv[2], argv[3], argv[4]);
  67.       printf("pmerge (%s, %s, %s, %s) returned:\n %s\n",
  68.             argv[1], argv[2], argv[3], argv[4], pathname);
  69. }
  70.